package com.iven.xie.fboot.file.fegin.hystrix;

import com.google.common.collect.Maps;
import com.iven.xie.fboot.file.fegin.ISysAccessoryService;
import com.iven.xie.fboot.platform.entity.SysAccessory;
import com.iven.xie.fboot.tools.result.ResultModel;
import com.iven.xie.fboot.tools.result.ResultStatus;
import com.iven.xie.fboot.tools.util.IDGen;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author iven.xie
 */
@Component
public class ISysAccessoryServiceHystrix implements ISysAccessoryService {

    private final Map<String, SysAccessory> accessoryService = Maps.newHashMap();

    @Override
    public ResultModel<String> upload(SysAccessory accessory) {
        accessory.setId(IDGen.genId());
        synchronized (accessory.getId()) {
            accessoryService.put(accessory.getId(), accessory);
        }
        return new ResultModel<>(ResultStatus.SUCCESS, accessory.getId());
    }

    @Override
    public ResultModel<SysAccessory> getById(String id) {
        return new ResultModel<>(ResultStatus.SUCCESS, accessoryService.get(id));
    }
}
